package com.spic.business.supervision.controller;

import com.spic.business.common.core.utils.poi.BusinessExcelUtil;
import com.spic.business.common.core.workflow.IWorkFlowService;
import com.spic.business.common.core.workflow.WorkFlowController;
import com.spic.business.supervision.domain.DocSupervision;
import com.spic.business.supervision.service.IDocSupervisionService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 公文督办
 */
@RestController
@RequestMapping("/docSupervision")
public class DocSupervisionController extends WorkFlowController {

    @Autowired
    private IDocSupervisionService docSupervisionService;

    /**
     * 查询公文督办列表
     */
    @PreAuthorize(hasPermi = "business:docSupervision:list")
    @GetMapping("/list")
    public TableDataInfo list(DocSupervision docSupervision)
    {
        startPage();
        List<DocSupervision> list = docSupervisionService.selectDocSupervisionList(docSupervision);
        return getDataTable(list);
    }

    /**
     * 导出公文督办列表
     */
    @PreAuthorize(hasPermi = "business:docSupervision:export")
    @Log(title = "公文督办", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DocSupervision docSupervision) throws IOException
    {
        List<DocSupervision> list = docSupervisionService.selectDocSupervisionList(docSupervision);
        ExcelUtil<DocSupervision> util = new BusinessExcelUtil<DocSupervision>(DocSupervision.class);
        util.exportExcel(response, list, "公文督办数据");
    }

    /**
     * 获取公文督办详细信息
     */
    @PreAuthorize(hasPermi = "business:docSupervision:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(docSupervisionService.selectDocSupervisionById(id));
    }

    /**
     * 新增公文督办
     */
    @PreAuthorize(hasPermi = "business:docSupervision:add")
    @Log(title = "公文督办", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DocSupervision docSupervision)
    {
        return AjaxResult.success(docSupervisionService.insertDocSupervision(docSupervision));
    }

    /**
     * 修改公文督办
     */
    @PreAuthorize(hasPermi = "business:docSupervision:edit")
    @Log(title = "公文督办", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DocSupervision docSupervision)
    {
        return toAjax(docSupervisionService.updateDocSupervision(docSupervision));
    }

    /**
     * 删除公文督办
     */
    @PreAuthorize(hasPermi = "business:docSupervision:remove")
    @Log(title = "公文督办", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(docSupervisionService.deleteDocSupervisionByIds(ids));
    }


    /**
     * 发送短信
     * @param id
     * @return
     */
    @PostMapping("/sendMsg")
    public AjaxResult test(@RequestBody String id){
        docSupervisionService.sendMsg(id);
        return AjaxResult.success();
    }

    @Override
    protected IWorkFlowService getService() {
        return docSupervisionService;
    }
}
